require(hexbin)
close = function(n) return(c(n,n[1]));
files = list.files("data\\weights")

matr = matrix(0, nrow = 300, ncol = 300)
xcont = c()
ycont = c()

n = length(files)
avgx = matrix(0,200)
avgy = matrix(0,200)

xlists = c()
ylists = c()


for(name in files){
	chaint = readLines(paste("data\\weights\\",name,sep=""),warn=0)
	chain = as.numeric(data.frame(strsplit(chaint,""))$c..)-1

	# convert chain to dx,dy
	chain = (chain+1)	%% 8
	dt = 1+(sqrt(2)-1) * (chain%%2)
	t = cumsum(dt)
	Tk = sum(dt)

	
	dx = sign(6-chain)*sign(2-chain)
	dy = -sign(4-chain)*sign(chain)
	x = cumsum(dx)
	y = cumsum(dy)
		
	# lines(x,y)
	# add to contour plot
	xcont = c(xcont,x)
	ycont = c(ycont,y)

	avgx = avgx + x[(0:199)/200*length(x)] 
	avgy = avgy + y[(0:199)/200*length(y)] 
}




#plot(hexbin(xcont,ycont))

#plot(xcont,ycont, col=rgb(0,0,0,4,maxColorValue=255), pch=16)

#plot(c(avgx,avgx[1]),c(avgy,avgy[1]),type="l")





